﻿using System;
using System.Diagnostics;
using battlenet.wow.rt.domain.objects;
using battlenet.wow.rt.sdk.data.dto;
using battlenet.wow.rt.sdk.utility;

namespace battlenet.wow.rt.sdk.objects.Mapper
{
    internal class CharacterItemMapper : Remapper<CharacterItems>
    {
        public override void RegisterMappers()
        {
            Register(typeof(CharacterItemsInfo), input => Map(input as CharacterItemsInfo));
        }

        internal CharacterItems Map(CharacterItemsInfo info)
        {
            Debug.WriteLine(string.Format("Mapping items..."));

            var items = new CharacterItems();
            items.AverageItemLevel = info.AverageItemLevel;
            items.AverageItemLevelEquipped = info.AverageItemLevelEquipped;
            items.Head = info.Head.Remap(new ItemMapper(SlotType.Head));
            items.Neck = info.Neck.Remap(new ItemMapper(SlotType.Neck));
            items.Shoulders = info.Shoulder.Remap(new ItemMapper(SlotType.Shoulders));
            items.Back = info.Back.Remap(new ItemMapper(SlotType.Back));
            items.Chest = info.Chest.Remap(new ItemMapper(SlotType.Chest));
            items.Shirt = info.Shirt.Remap(new ItemMapper(SlotType.Shirt));
            items.Wrist = info.Wrist.Remap(new ItemMapper(SlotType.Wrist));
            items.Hands = info.Hands.Remap(new ItemMapper(SlotType.Hands));
            items.Waist = info.Waist.Remap(new ItemMapper(SlotType.Waist));
            items.Legs = info.Legs.Remap(new ItemMapper(SlotType.Legs));
            items.Feet = info.Feet.Remap(new ItemMapper(SlotType.Feet));
            items.Finger1 = info.Finger1.Remap(new ItemMapper(SlotType.Finger1));
            items.Finger2 = info.Finger2.Remap(new ItemMapper(SlotType.Finger2));
            items.Trinket1 = info.Trinket1.Remap(new ItemMapper(SlotType.Trinket1));
            items.Trinket2 = info.Trinket2.Remap(new ItemMapper(SlotType.Trinket2));
            items.MainHand = info.MainHand.Remap(new WeaponItemMapper(SlotType.MainHand));
            items.OffHand = info.OffHand != null ? info.OffHand.Remap(new ItemMapper(SlotType.OffHand)) : null;

            Debug.WriteLine(string.Format("Mapping items complete!"));
            return items;
        }
    }
}